
@extends('admin.layouts.app')

@section('content')

    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">商品品牌</strong> / <small>Good Brands</small></div>
            </div>

            <hr>

           @if(session('brand'))
                <div class="am-g">
                    <div class="am-u-md-12">
                        <div class="am-alert am-alert-success">
                            {{session('brand')}}
                        </div>
                    </div>
                </div>
               @endif

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{{route('shop.brand.create')}}"  class="am-btn am-btn-default"><span class="am-icon-plus"></span> 新增</a>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <form action="{{route('shop.brand.index')}}" method="get" >
                        {{--{!! csrf_field() !!}--}}
                    <div class="am-input-group am-input-group-sm">

                            <input type="text" name="keyword" class="am-form-field">
                              <span class="am-input-group-btn" >
                                <button  class="am-btn am-btn-default" type="submit" >搜索</button>
                              </span>

                    </div>
                    </form>
                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    {{--<form class="am-form">--}}
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-id">ID</th>
                                <th class="table-thumb">缩略图</th>
                                <th class="table-name">品牌名称</th>
                                <th>品牌商品</th>
                                <th class="table-desc">品牌描述</th>
                                <th class="table-is-show am-hide-sm-only">是否显示</th>
                                <th class="table-sort-order am-hide-sm-only" style="width:10%">排序</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($brands as $brand)
                            <tr data-id="{{$brand->id}}">

                                <td>{{$brand->id}}</td>
                                <td>
                                    @if($brand->thumb)<img src="{{$brand->thumb}}" alt class="thumb" style="height: 60px">@endif
                                </td>
                                <td>{{$brand->name}}</td>
                                <td class="am-hide-sm-only">商品-预留</td>
                                <td class="am-hide-sm-only">{{$brand->desc}}</td>
                                <td class="am-hide-sm-only">
                                   {{-- <span class="{{$brand->is_show==0?'am-icon-close':'am-icon-check'}} is_something" data-attr="is_show"></span>--}}
                                    {!!is_show('is_show',$brand)!!}
                                </td>
                                <td class="am-hide-sm-only">
                                    <input type="text" name="sort_order" class="am-input-sm" value="{{$brand->sort_order}}">
                                </td>
                                <td>
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                            <a href="{{route('shop.brand.edit',[$brand->id])}}" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</a>

                        <form action="{{route('shop.brand.destroy',[$brand->id])}}" method="post" style="float: left;display: inline">
                            {!! csrf_field() !!}
                            {!! method_field('delete') !!}
                            <button  type="submit" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="return confirm('确定要删除吗')" ><span class="am-icon-trash-o"></span> 删除</button>
                        </form>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                           @endforeach
                            </tbody>
                        </table>


                        <div class="am-cf" style="float: right">

                            {!! $brands->appends(Request::all())->links() !!}

                        </div>
                        <hr />
                        <p>共{{$brands->total()}}条记录</p>


                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>

    </div>

@endsection

@section('js')
    {{--<script src="laravel.js"></script>--}}
 <script>

     $(function(){

         /*$.ajaxSetup({
             headers: {
                 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
             }
         });*/


         //是否显示
         $('.is_something').click(function(){
             var _this=$(this);
             id=$(this).parents("tr").attr('data-id');
             $.ajax({
                 url:"{{url('/shop/brand/is_show')}}",
                 type:'patch',
                 data:{id:id},
                 success:function (data) {
                     console.log(data);
                     _this.toggleClass('am-icon-close am-icon-check');
                 }
             });
         })


         //排序
         $("input[name='sort_order']").change(function () {
             var data = {
                 sort_order: $(this).val(),
                 id: $(this).parents("tr").attr('data-id')
             }

             $.ajax({
                 type: "patch",
                 url:"{{url('/shop/brand/sort_order')}}",
                 data: data,
             });
         })


     })
 </script>

@endsection